﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>员工面板</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<script src="../../scripts/boot.js" type="text/javascript"></script>


<style type="text/css">
html, body {
	padding: 0;
	margin: 0;
	border: 0;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>

	<form id="form1" method="post">
		<input name="id" class="mini-hidden" />
		<div style="padding-left: 11px; padding-bottom: 5px;">
			<table style="table-layout: fixed;">
				<tr>
					<td style="display: none; width: 150px;"><input name="userid"
						class="mini-textbox" required="true" emptyText="顾客编号" /></td>
					<td style="width: 80px;">顾客姓名</td>
					<td><input name="username" class="mini-textbox" required="true" />
					</td>
					<!--<td style="width:150px;">    -->
				</tr>
				<tr>
					<td>密码</td>
					<td><input name="password" class="mini-textbox" required="true" />
					</td>
					<td>电话</td>
					<td><input name="phone" class="mini-textbox" required="true" />

						<!--<input name="remark" class="mini-combobox" valueField="id" textField="name"/>-->
					</td>
				</tr>

			</table>
		</div>

		<div style="text-align: center; padding: 10px;">
			<a class="mini-button" onclick="onOk"
				style="width: 60px; margin-right: 20px;">确定</a> <a
				class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
		</div>
	</form>
	<script type="text/javascript">
        mini.parse();


        var form = new mini.Form("form1");// new  FormData()

        function remove() {

            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        console.log(r);
                        ids.push(r.id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({

                        success: function (text) {
                            grid.reload();
                        },
                        error: function () {
                        }
                    });
                }
            } else {
                alert("请选中一条记录");
            }
        }
        function SaveData() {
            var o = form.getData();

            form.validate();
            if (form.isValid() == false) return;

            var json = mini.encode([o]);
            console.log(json)//向控制台
            if (method == "insert") {
            $.ajax({
                url: "../../customer/insert",//增加 date 里面style 是因为         style.html 里面var style = { action: "new"};

                // type: 'post',
				// data: { customer: json ,method:method},
                contentType: 'application/json',
                type: 'post',
                data:JSON.stringify(o),
                cache: false,
                success: function (text) {
                    CloseWindow("save");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        } else {
                $.ajax({
                    url: "../../customer/update",

                    contentType: 'application/json',//新
                    type: 'post',
                    data: JSON.stringify(o),
                    // data: {style: json},
                    cache: false,
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                        CloseWindow();
                    }
                });
            }
        }

        // var method="insert"//区分
        //////////////////
      //  标准方法接口定义
        function SetData(data) {
            method=data.action
            if (data.action == "update") {

                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                var  styledata=data.styledata
                console.log(styledata)
                console.log(typeof styledata)//字符串
                styledata=JSON.parse(styledata)//使用 JSON.parse()解析为 JavaScript 对象
                form.setData(styledata)
            //

            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {            
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        function onOk(e) {
            SaveData();
            //UpSaveData();
            // SetData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        //////////////////////////////////
       



    </script>
</body>
</html>
